
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/29/2011 18:24:19
-- Generated from EDMX file: D:\TGI-Project\TicketApp\TicketApp.DataService\TicketsModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TicketAppDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_EventAgent_Event]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventAgent] DROP CONSTRAINT [FK_EventAgent_Event];
GO
IF OBJECT_ID(N'[dbo].[FK_EventAgent_Agent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventAgent] DROP CONSTRAINT [FK_EventAgent_Agent];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AllUsers] DROP CONSTRAINT [FK_UserAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AllUsers] DROP CONSTRAINT [FK_UserRole];
GO
IF OBJECT_ID(N'[dbo].[FK_VenueAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Venues] DROP CONSTRAINT [FK_VenueAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTypeTicketQuota]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketQuotas] DROP CONSTRAINT [FK_TicketTypeTicketQuota];
GO
IF OBJECT_ID(N'[dbo].[FK_AgentBranchAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AgentBranches] DROP CONSTRAINT [FK_AgentBranchAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_AgentBranchTicketQuota]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketQuotas] DROP CONSTRAINT [FK_AgentBranchTicketQuota];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTicketQuota]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tickets] DROP CONSTRAINT [FK_TicketTicketQuota];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTypeContact]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contacts] DROP CONSTRAINT [FK_TicketTypeContact];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTemplateTicketType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketTypes] DROP CONSTRAINT [FK_TicketTemplateTicketType];
GO
IF OBJECT_ID(N'[dbo].[FK_ContactAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contacts] DROP CONSTRAINT [FK_ContactAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_PaymentModePayment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Payments] DROP CONSTRAINT [FK_PaymentModePayment];
GO
IF OBJECT_ID(N'[dbo].[FK_PaymentTicket1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tickets] DROP CONSTRAINT [FK_PaymentTicket1];
GO
IF OBJECT_ID(N'[dbo].[FK_UserEvent_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserEvent] DROP CONSTRAINT [FK_UserEvent_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserEvent_Event]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserEvent] DROP CONSTRAINT [FK_UserEvent_Event];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAgentBranch]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AgentBranches] DROP CONSTRAINT [FK_UserAgentBranch];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPayment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Payments] DROP CONSTRAINT [FK_UserPayment];
GO
IF OBJECT_ID(N'[dbo].[FK_UserTicket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tickets] DROP CONSTRAINT [FK_UserTicket];
GO
IF OBJECT_ID(N'[dbo].[FK_EventEventVenue]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventVenues] DROP CONSTRAINT [FK_EventEventVenue];
GO
IF OBJECT_ID(N'[dbo].[FK_VenueEventVenue]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventVenues] DROP CONSTRAINT [FK_VenueEventVenue];
GO
IF OBJECT_ID(N'[dbo].[FK_EventVenueTicketType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketTypes] DROP CONSTRAINT [FK_EventVenueTicketType];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Events]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Events];
GO
IF OBJECT_ID(N'[dbo].[Addresses]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Addresses];
GO
IF OBJECT_ID(N'[dbo].[Contacts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contacts];
GO
IF OBJECT_ID(N'[dbo].[TicketTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketTypes];
GO
IF OBJECT_ID(N'[dbo].[AllUsers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AllUsers];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[TicketQuotas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketQuotas];
GO
IF OBJECT_ID(N'[dbo].[Venues]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Venues];
GO
IF OBJECT_ID(N'[dbo].[AgentBranches]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AgentBranches];
GO
IF OBJECT_ID(N'[dbo].[Tickets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tickets];
GO
IF OBJECT_ID(N'[dbo].[PaymentModes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PaymentModes];
GO
IF OBJECT_ID(N'[dbo].[TicketTemplates]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketTemplates];
GO
IF OBJECT_ID(N'[dbo].[Payments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Payments];
GO
IF OBJECT_ID(N'[dbo].[EventVenues]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventVenues];
GO
IF OBJECT_ID(N'[dbo].[EventAgent]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventAgent];
GO
IF OBJECT_ID(N'[dbo].[UserEvent]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserEvent];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Events'
CREATE TABLE [dbo].[Events] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [StartDateTime] datetime  NOT NULL,
    [EndDateTime] datetime  NOT NULL,
    [Timezone] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Status] int  NOT NULL
);
GO

-- Creating table 'Addresses'
CREATE TABLE [dbo].[Addresses] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Line1] nvarchar(max)  NOT NULL,
    [Line2] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [Country] nvarchar(max)  NOT NULL,
    [PostalCode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Contacts'
CREATE TABLE [dbo].[Contacts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [TicketTypeContact_Contact_Id] int  NULL,
    [Address_Id] int  NULL
);
GO

-- Creating table 'TicketTypes'
CREATE TABLE [dbo].[TicketTypes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [TotalQuantity] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [EventDate] datetime  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [CustomTemplate] nvarchar(max)  NULL,
    [TicketTemplate_Id] int  NULL,
    [EventVenue_Id] int  NOT NULL
);
GO

-- Creating table 'AllUsers'
CREATE TABLE [dbo].[AllUsers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [Status] int  NOT NULL,
    [__Disc__] nvarchar(4000)  NOT NULL,
    [Address_Id] int  NOT NULL,
    [Role_Id] int  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TicketQuotas'
CREATE TABLE [dbo].[TicketQuotas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [QuotaQuantity] int  NOT NULL,
    [TicketType_Id] int  NOT NULL,
    [AgentBranch_Id] int  NOT NULL
);
GO

-- Creating table 'Venues'
CREATE TABLE [dbo].[Venues] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Address_Id] int  NOT NULL
);
GO

-- Creating table 'AgentBranches'
CREATE TABLE [dbo].[AgentBranches] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Address_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'Tickets'
CREATE TABLE [dbo].[Tickets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [PhysicalTicketNumber] nvarchar(max)  NOT NULL,
    [EventDate] datetime  NOT NULL,
    [ElectornicTicketNumber] uniqueidentifier  NOT NULL,
    [Barcode] nvarchar(max)  NOT NULL,
    [TicketQuota_Id] int  NOT NULL,
    [Payment_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'PaymentModes'
CREATE TABLE [dbo].[PaymentModes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Mode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TicketTemplates'
CREATE TABLE [dbo].[TicketTemplates] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Template] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Payments'
CREATE TABLE [dbo].[Payments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] nvarchar(max)  NOT NULL,
    [SuccessfulPayment] bit  NOT NULL,
    [PaymentMode_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'EventVenues'
CREATE TABLE [dbo].[EventVenues] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Event_Id] int  NOT NULL,
    [Venue_Id] int  NOT NULL
);
GO

-- Creating table 'EventAgent'
CREATE TABLE [dbo].[EventAgent] (
    [EventAgent_Agent_Id] int  NOT NULL,
    [Agents_Id] int  NOT NULL
);
GO

-- Creating table 'UserEvent'
CREATE TABLE [dbo].[UserEvent] (
    [User_Id] int  NOT NULL,
    [OrganizerOrAgents_Events_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Events'
ALTER TABLE [dbo].[Events]
ADD CONSTRAINT [PK_Events]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Addresses'
ALTER TABLE [dbo].[Addresses]
ADD CONSTRAINT [PK_Addresses]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [PK_Contacts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [PK_TicketTypes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AllUsers'
ALTER TABLE [dbo].[AllUsers]
ADD CONSTRAINT [PK_AllUsers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TicketQuotas'
ALTER TABLE [dbo].[TicketQuotas]
ADD CONSTRAINT [PK_TicketQuotas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Venues'
ALTER TABLE [dbo].[Venues]
ADD CONSTRAINT [PK_Venues]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AgentBranches'
ALTER TABLE [dbo].[AgentBranches]
ADD CONSTRAINT [PK_AgentBranches]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [PK_Tickets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PaymentModes'
ALTER TABLE [dbo].[PaymentModes]
ADD CONSTRAINT [PK_PaymentModes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TicketTemplates'
ALTER TABLE [dbo].[TicketTemplates]
ADD CONSTRAINT [PK_TicketTemplates]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Payments'
ALTER TABLE [dbo].[Payments]
ADD CONSTRAINT [PK_Payments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EventVenues'
ALTER TABLE [dbo].[EventVenues]
ADD CONSTRAINT [PK_EventVenues]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [EventAgent_Agent_Id], [Agents_Id] in table 'EventAgent'
ALTER TABLE [dbo].[EventAgent]
ADD CONSTRAINT [PK_EventAgent]
    PRIMARY KEY NONCLUSTERED ([EventAgent_Agent_Id], [Agents_Id] ASC);
GO

-- Creating primary key on [User_Id], [OrganizerOrAgents_Events_Id] in table 'UserEvent'
ALTER TABLE [dbo].[UserEvent]
ADD CONSTRAINT [PK_UserEvent]
    PRIMARY KEY NONCLUSTERED ([User_Id], [OrganizerOrAgents_Events_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [EventAgent_Agent_Id] in table 'EventAgent'
ALTER TABLE [dbo].[EventAgent]
ADD CONSTRAINT [FK_EventAgent_Event]
    FOREIGN KEY ([EventAgent_Agent_Id])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Agents_Id] in table 'EventAgent'
ALTER TABLE [dbo].[EventAgent]
ADD CONSTRAINT [FK_EventAgent_Agent]
    FOREIGN KEY ([Agents_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventAgent_Agent'
CREATE INDEX [IX_FK_EventAgent_Agent]
ON [dbo].[EventAgent]
    ([Agents_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'AllUsers'
ALTER TABLE [dbo].[AllUsers]
ADD CONSTRAINT [FK_UserAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAddress'
CREATE INDEX [IX_FK_UserAddress]
ON [dbo].[AllUsers]
    ([Address_Id]);
GO

-- Creating foreign key on [Role_Id] in table 'AllUsers'
ALTER TABLE [dbo].[AllUsers]
ADD CONSTRAINT [FK_UserRole]
    FOREIGN KEY ([Role_Id])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRole'
CREATE INDEX [IX_FK_UserRole]
ON [dbo].[AllUsers]
    ([Role_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'Venues'
ALTER TABLE [dbo].[Venues]
ADD CONSTRAINT [FK_VenueAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VenueAddress'
CREATE INDEX [IX_FK_VenueAddress]
ON [dbo].[Venues]
    ([Address_Id]);
GO

-- Creating foreign key on [TicketType_Id] in table 'TicketQuotas'
ALTER TABLE [dbo].[TicketQuotas]
ADD CONSTRAINT [FK_TicketTypeTicketQuota]
    FOREIGN KEY ([TicketType_Id])
    REFERENCES [dbo].[TicketTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTypeTicketQuota'
CREATE INDEX [IX_FK_TicketTypeTicketQuota]
ON [dbo].[TicketQuotas]
    ([TicketType_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'AgentBranches'
ALTER TABLE [dbo].[AgentBranches]
ADD CONSTRAINT [FK_AgentBranchAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgentBranchAddress'
CREATE INDEX [IX_FK_AgentBranchAddress]
ON [dbo].[AgentBranches]
    ([Address_Id]);
GO

-- Creating foreign key on [AgentBranch_Id] in table 'TicketQuotas'
ALTER TABLE [dbo].[TicketQuotas]
ADD CONSTRAINT [FK_AgentBranchTicketQuota]
    FOREIGN KEY ([AgentBranch_Id])
    REFERENCES [dbo].[AgentBranches]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgentBranchTicketQuota'
CREATE INDEX [IX_FK_AgentBranchTicketQuota]
ON [dbo].[TicketQuotas]
    ([AgentBranch_Id]);
GO

-- Creating foreign key on [TicketQuota_Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [FK_TicketTicketQuota]
    FOREIGN KEY ([TicketQuota_Id])
    REFERENCES [dbo].[TicketQuotas]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTicketQuota'
CREATE INDEX [IX_FK_TicketTicketQuota]
ON [dbo].[Tickets]
    ([TicketQuota_Id]);
GO

-- Creating foreign key on [TicketTypeContact_Contact_Id] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_TicketTypeContact]
    FOREIGN KEY ([TicketTypeContact_Contact_Id])
    REFERENCES [dbo].[TicketTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTypeContact'
CREATE INDEX [IX_FK_TicketTypeContact]
ON [dbo].[Contacts]
    ([TicketTypeContact_Contact_Id]);
GO

-- Creating foreign key on [TicketTemplate_Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [FK_TicketTemplateTicketType]
    FOREIGN KEY ([TicketTemplate_Id])
    REFERENCES [dbo].[TicketTemplates]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTemplateTicketType'
CREATE INDEX [IX_FK_TicketTemplateTicketType]
ON [dbo].[TicketTypes]
    ([TicketTemplate_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_ContactAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContactAddress'
CREATE INDEX [IX_FK_ContactAddress]
ON [dbo].[Contacts]
    ([Address_Id]);
GO

-- Creating foreign key on [PaymentMode_Id] in table 'Payments'
ALTER TABLE [dbo].[Payments]
ADD CONSTRAINT [FK_PaymentModePayment]
    FOREIGN KEY ([PaymentMode_Id])
    REFERENCES [dbo].[PaymentModes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PaymentModePayment'
CREATE INDEX [IX_FK_PaymentModePayment]
ON [dbo].[Payments]
    ([PaymentMode_Id]);
GO

-- Creating foreign key on [Payment_Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [FK_PaymentTicket1]
    FOREIGN KEY ([Payment_Id])
    REFERENCES [dbo].[Payments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PaymentTicket1'
CREATE INDEX [IX_FK_PaymentTicket1]
ON [dbo].[Tickets]
    ([Payment_Id]);
GO

-- Creating foreign key on [User_Id] in table 'UserEvent'
ALTER TABLE [dbo].[UserEvent]
ADD CONSTRAINT [FK_UserEvent_User]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [OrganizerOrAgents_Events_Id] in table 'UserEvent'
ALTER TABLE [dbo].[UserEvent]
ADD CONSTRAINT [FK_UserEvent_Event]
    FOREIGN KEY ([OrganizerOrAgents_Events_Id])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserEvent_Event'
CREATE INDEX [IX_FK_UserEvent_Event]
ON [dbo].[UserEvent]
    ([OrganizerOrAgents_Events_Id]);
GO

-- Creating foreign key on [User_Id] in table 'AgentBranches'
ALTER TABLE [dbo].[AgentBranches]
ADD CONSTRAINT [FK_UserAgentBranch]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAgentBranch'
CREATE INDEX [IX_FK_UserAgentBranch]
ON [dbo].[AgentBranches]
    ([User_Id]);
GO

-- Creating foreign key on [User_Id] in table 'Payments'
ALTER TABLE [dbo].[Payments]
ADD CONSTRAINT [FK_UserPayment]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserPayment'
CREATE INDEX [IX_FK_UserPayment]
ON [dbo].[Payments]
    ([User_Id]);
GO

-- Creating foreign key on [User_Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [FK_UserTicket]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserTicket'
CREATE INDEX [IX_FK_UserTicket]
ON [dbo].[Tickets]
    ([User_Id]);
GO

-- Creating foreign key on [Event_Id] in table 'EventVenues'
ALTER TABLE [dbo].[EventVenues]
ADD CONSTRAINT [FK_EventEventVenue]
    FOREIGN KEY ([Event_Id])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventEventVenue'
CREATE INDEX [IX_FK_EventEventVenue]
ON [dbo].[EventVenues]
    ([Event_Id]);
GO

-- Creating foreign key on [Venue_Id] in table 'EventVenues'
ALTER TABLE [dbo].[EventVenues]
ADD CONSTRAINT [FK_VenueEventVenue]
    FOREIGN KEY ([Venue_Id])
    REFERENCES [dbo].[Venues]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VenueEventVenue'
CREATE INDEX [IX_FK_VenueEventVenue]
ON [dbo].[EventVenues]
    ([Venue_Id]);
GO

-- Creating foreign key on [EventVenue_Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [FK_EventVenueTicketType]
    FOREIGN KEY ([EventVenue_Id])
    REFERENCES [dbo].[EventVenues]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventVenueTicketType'
CREATE INDEX [IX_FK_EventVenueTicketType]
ON [dbo].[TicketTypes]
    ([EventVenue_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------